﻿//********************************************************************************//
//创建日期：<创建日期，2016-10-28>
//创建作者：<郭登杰，guodengjie@shanghai3h.com>
//功能说明：来涵加价水量调整信息
//********************************************************************************//
using BLL;
using BLL.Access;
using Entity;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Web.Class;
using Web.Controls.LAIHAN;

namespace Web.Controls
{
    public partial class UCLHJiaJiaSLInfoQS : System.Web.UI.UserControl, IUCLHOperate
    {
        #region 属性

        /// <summary>
        /// 来函类型
        /// </summary>
        public eLaiHanLX LaiHanLX
        {
            get;
            set;
        }

        /// <summary>
        /// 当前流程
        /// </summary>
        public eLaiHanLCBH LaiHanLC
        {
            get;
            set;
        }

    

        /// <summary>
        /// 用户名
        /// </summary>
        public string YONGHUM
        {
            set
            {
                this.txtYongHuM.Text = value;
            }
            get
            {
                return this.txtYongHuM.Text;
            }
        }

      
        /// <summary>
        /// 来函编号
        /// </summary>
        public string LAIHANBH
        {
            set
            {
                this.txtLaiHanBH.Text = value;
            }
            get
            {
                return this.txtLaiHanBH.Text;
            }
        }

       

        /// <summary>
        /// 判断引用页面类别   1月调整登记  2月调整修改  3其他页面调用 不可修改
        /// </summary>
        public int ControlType
        {
            get { return Convert.ToInt32(ViewState["ControlType"]); }
            set { ViewState["ControlType"] = value; }
        }

        /// <summary>
        /// 记录错误日志
        /// </summary>
        private string errorMsg
        {
            get
            {
                return Convert.ToString(ViewState["errorMsg"]);
            }
            set
            {
                ViewState["errorMsg"] = value;
            }
        }

        #endregion

        #region 变量

        #endregion

        #region 事件

        /// <summary>
        /// 加载事件
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitControl();
            }
        }

        /// <summary>
        /// 回调响应
        /// </summary>
        protected void ASPxCallback1_Callback(object source, DevExpress.Web.CallbackEventArgs e)
        {
            CallbackResult cr = new CallbackResult(e.Parameter);
            if (e.Parameter == "bh")//响应编号回车事件
            {
                DataRowCollection drc=SearchSpHelper.P_QS_JJSLXXHQ(null,Convert.ToInt32(this.cmbY.Value),this.txtYongHuH.Text).Tables[0].Rows;
                if (drc.Count == 0)
                {
                    cr.IsSuccess = false;
                    cr.IsAlertMsg = true;
                    cr.Msg = "该用户不存在";
                    e.Result = cr.ToString();
                }
                else
                {
                    cr.IsSuccess = true;
                    cr.IsAlertMsg = false;
                    cr.AddValue(Convert.ToString(drc[0]["S_YONGHUM"]),Convert.ToString(drc[0]["I_KCJHYUAN"]),Convert.ToString(drc[0]["I_KCJHXIN"]),Convert.ToString(drc[0]["I_HGJHYUAN"]),
                                Convert.ToString(drc[0]["I_KCLSJ"]), Convert.ToString(drc[0]["I_HGLSJ"]), Convert.ToString(drc[0]["I_CJHL"]), Convert.ToString(drc[0]["I_JJL"]), Convert.ToString(drc[0]["I_TZL"]));
                    e.Result = cr.ToString();
                }
            }
        }

        /// <summary>
        /// 前台验证后实际执行后台操作
        /// </summary>
        protected void btnActPerform_Click(object sender, EventArgs e)
        {
            //将当前调整用户添加到列表
            QS_LH_JIAJIATZXX item = new QS_LH_JIAJIATZXX();
            item.I_CJHL = int.Parse(this.txtCJHL.Text);
            item.I_HGJHYUAN = int.Parse(this.txtHGJHYUAN.Text);
            item.I_HGLSJ = int.Parse(this.txtHGLSJ.Text);
            item.I_JJL = int.Parse(this.txtJJL.Text);
            item.I_KCJHXIN = int.Parse(this.txtKCJHXIN.Text);
            item.I_KCJHYUAN= int.Parse(this.txtKCJHYUAN.Text);
            item.I_KCLSJ = int.Parse(this.txtKCLSJ.Text);
            item.I_TZL = int.Parse(this.txtTZL.Text);
            item.I_Y = Convert.ToInt32(this.cmbY.Value);
            item.S_YONGHUH = this.txtYongHuH.Text;
            item.S_YONGHUM = this.txtYongHuM.Text;
            UCLHJIAJIAXXListQS ucin = this.Parent.FindControl("UCLHJIAJIAXXListQS") as UCLHJIAJIAXXListQS;
            ucin.AddItem(item);
            this.ClearInfo();
            this.cmbY.SelectedIndex = 0;
            this.txtYongHuH.Focus();
        }

        #endregion

        #region 方法

        /// <summary>
        /// 配置控件
        /// </summary>
        public void InitControl()
        {
            this.txtCJHL.ClientEnabled = false;
            this.txtHGJHYUAN.ClientEnabled = false;
            this.txtHGLSJ.ClientEnabled = false;
            this.txtJJL.ClientEnabled = false;
            this.txtKCJHXIN.ClientEnabled = false;
            this.txtKCJHYUAN.ClientEnabled = false;
            this.txtKCLSJ.ClientEnabled = false;
            this.txtLaiHanBH.ClientEnabled = false;
            this.txtTZL.ClientEnabled = true;
            this.txtXuKeZH.ClientEnabled = false;
            this.txtYongHuH.ClientEnabled = true;
            this.txtYongHuM.ClientEnabled = false;
            this.cmbY.ClientEnabled = true;
            int y = BusinessTool.GetSLYMorZWNY(1,BusinessTool.WType)/100;
            for (int i = y; i >= y-1; i--)
            {
                this.cmbY.Items.Add(i.ToString());
            }
            this.cmbY.SelectedIndex = 0;
            this.txtYongHuH.Focus();
        }

        /// <summary>
        ///根据当前流程状态设置步骤显示
        /// </summary>
        private void SetDisplay()
        {
            //根据类型显示需要的             
            //受理之后不可编辑.下方switch中case 3可去除.使用此控件的受理之后的页面该控件属性需加上LaiHanLC="受理"
            if ((int)this.LaiHanLC < (int)eLaiHanLCBH.预登记)
            {
                this.txtYongHuH.ClientEnabled = true;
                this.txtTZL.ClientEnabled = true;
                this.cmbY.ClientEnabled = true;

            }
            else if ((int)this.LaiHanLC == (int)eLaiHanLCBH.预登记)
            {
                this.txtYongHuH.ClientEnabled = true;
                this.txtTZL.ClientEnabled = true;
                this.cmbY.ClientEnabled = false;
            }
            else if ((int)this.LaiHanLC > (int)eLaiHanLCBH.预登记)
            {
                this.txtYongHuH.ClientEnabled = false;
                this.txtTZL.ClientEnabled = false;
                this.cmbY.ClientEnabled = false;
                this.trdj1.Visible = false;
                this.trdj2.Visible = false;
                this.trdj3.Visible = false;
                this.trdj4.Visible = false;
                this.trdj5.Visible = false;
                this.trdj6.Visible = false;
                this.trdj7.Visible = false;
            }
        }

        /// <summary>
        /// 验证数据
        /// </summary>
        public ValidateRS Validate()
        {
            ValidateRS rs = new ValidateRS();
            if (this.LaiHanLC == eLaiHanLCBH.未登记)
            {
               
            }       
            rs.IsSuccess = true;
            return rs;
        }

        /// <summary>
        /// 清除数据
        /// </summary>
        public void ClearInfo()
        {
            this.txtCJHL.Text = "";
            this.txtHGJHYUAN.Text = "";
            this.txtHGLSJ.Text = "";
            this.txtJJL.Text = "";
            this.txtKCJHXIN.Text = "";
            this.txtKCJHYUAN.Text = "";
            this.txtKCLSJ.Text = "";
            this.txtLaiHanBH.Text = "";
            this.txtTZL.Text = "";
            this.txtXuKeZH.Text = "";
            this.txtYongHuH.Text = "";
            this.txtYongHuM.Text = "";
            this.cmbY.Text = "";
        }
   

        /// <summary>
        /// 根据来函加载信息
        /// </summary>
        public void LoadInfo(YS_LH_LAIHANXX laihanxx)
        {
            //登记前
            if (laihanxx.ID == 0)
            {
                this.LaiHanLC = eLaiHanLCBH.未登记;
                SetDisplay();
                return;
            }
            else
            {
                this.LaiHanLC = (eLaiHanLCBH)Enum.Parse(typeof(eLaiHanLCBH), laihanxx.I_LIUCHENGBH.ToString());
                SetDisplay();
            }            
            //加载许可号等信息
            this.LAIHANBH = laihanxx.S_LAIHANBH;
            this.txtXuKeZH.Text = laihanxx.S_XUKEBH;           
        }

        /// <summary>
        /// 获取来函主表信息
        /// </summary>
        /// <param name="laihanid">ID</param>
        /// <param name="liuchengzt">0:收件 1:收件并登记</param>
        /// <param name="msg">输出消息,正常为空</param>
        /// <returns>null:验证失败 !null:成功返回</returns>
        public YS_LH_LAIHANXX GetLAIHANXX(int laihanid, int liuchengzt, out string msg)
        {
            YS_LH_LAIHANXX laihan = new YS_LH_LAIHANXX();
            string laihanbh = "";
            string xukebh = "";
            msg = "";
            laihan.ID = laihanid;
            if (laihanid == 0)
            {
                string zd, glk, ywy;
                PageTools.GetLHDJZDGLKYWY(null, out zd, out glk, out ywy);
                laihan.S_ZHANDIANBH = zd;
                laihan.S_GUANLIKBH = glk;
                laihan.I_YWY = int.Parse(ywy);
                laihan.S_YWY = BusinessTool.GetYWYName(ywy);
                //laihan.S_YHYWY = ywy;
                DataSet numset = new SpHelper().P_YS_LH_XUKEBH(glk, 1, 0, (BusinessTool.GetWaterYM() / 100).ToString(), out xukebh, out laihanbh);                
                new SpHelper().P_ALL_LH_BHSC(BusinessTool.WType, (int)this.LaiHanLX, BusinessTool.GetWaterYM() / 100, out laihanbh);
                laihan.I_XT = BusinessTool.WType;
                laihan.D_SHURURQ = DateTime.Now;
                laihan.D_LAIHANRQ = DateTime.Now;
                laihan.I_JLZT = 0;
                laihan.I_LAIHANLX = (int)this.LaiHanLX;
                laihan.I_SHURUR = LoginInfo.CurrentUser.UserID;
                laihan.I_AUTOTYPE = 0;
                laihan.S_LAIHANBH = laihanbh;
                laihan.S_BEIYONG1 = xukebh;
                laihan.S_XUKEBH = xukebh;
                laihan.I_LIUCHENGZT = (int)eLaiHanLCZT.流程中;
                //laihan.I_Y = BusinessTool.GetWaterYM() / 100;
                laihan.I_TZY = laihan.I_Y = Convert.ToInt32(this.cmbY.Value);
                //laihan.I_M = BusinessTool.GetWaterYM() % 100;
            }
            else
            {
                laihan = new YS_LH_LAIHANXXProcess().SelectYS_LH_LAIHANXX(laihan.ID);
            }
            laihan.I_LIUCHENGBH = liuchengzt;
            laihan.S_CAOZUOR = LoginInfo.CurrentUser.UserID.ToString();
            laihan.D_CAOZUOSJ = BusinessTool.GetDataBaseDateTime();
            return laihan;
        }

        /// <summary>
        /// 获取来函用户信息
        /// </summary>
        /// <param name="laihan"></param>
        /// <returns></returns>
        public YS_LH_YONGHUXX GetLHYONGHUXX(YS_LH_LAIHANXX laihan)
        {            
            return null;
        }
       
        #endregion


    }
}